package com.china08.yxyapi.api.manage.tec.teaching.mistakes;

import java.sql.Timestamp;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.mistakes.TeaMistakesQues;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.repository.mg.mistakes.TeaMistakesQuesRepository;

/**
 * 教师修改错题是否解决状态
 * 
 * @author Administrator
 *
 */
@CrossOrigin
@RestController
public class TeaMistakesQuesStatusUdpController extends YxyApiBaseController {

    @Autowired
    TeaMistakesQuesRepository teaMistakesQuesRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/mistakes/mistakesquesstatus/udp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel model) {
        TeaMistakesQues tmq = teaMistakesQuesRepository.findOne(model.id);
        Assert.notNull(tmq, "未找到班级下的错题");
        tmq.setStatus(model.status);
        tmq.setCreatedDate(new Timestamp(new Date().getTime()));
        teaMistakesQuesRepository.save(tmq);
    }

    /**
     * 请求参数
     * 
     */
    protected static class ReqModel extends YxyApiReqModel {
        // id
        public String id;

        // 0--未解决 1--已解决
        public Integer status;
    }

}
